package com.example.portal.colmapping.controller;


import com.example.portal.colmapping.service.ColMappingServiceImpl;
import com.example.util.PageResult;
import com.example.util.ResponseMsg;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/col-mapping")
public class ColMappingController {

   @Resource
   ColMappingServiceImpl colMappingService;

    /**
     * 查询数据
     * @param params
     * @return
     */
    @RequestMapping("/getMappings")
    public ResponseMsg getMappings(@RequestParam Map<String,Object> params){
        try {

            PageResult pageResult= colMappingService.getMappings(params);
            return ResponseMsg.success(pageResult.getData(),pageResult.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            return ResponseMsg.fail(-1,e.getMessage());
        }
    }
    /**
     * 增加新的记录
     * @return
     */
    @RequestMapping("/insertMappings")
    public ResponseMsg insertMappings(@RequestBody Map<String,Object> params){
        try {
            colMappingService.insertMappings(params);
            return ResponseMsg.success("success");
        }catch (Exception e){
            e.printStackTrace();
            return ResponseMsg.fail(-1,e.getMessage());
        }
    }

    /**
     * 根据id删除
     * @param param
     * @return
     */
    @RequestMapping("/delMappings")
    public ResponseMsg delMappings(@RequestBody Map<String,Object> param){
        try {
            colMappingService.delMappings(param);
            return ResponseMsg.success("success");
        }catch (Exception e){
            e.printStackTrace();
            return ResponseMsg.fail(-1,e.getMessage());
        }
    }

    /**
     * 保存
     * @param params
     * @return
     */
    @RequestMapping("/updateMappings")
    public ResponseMsg updateMappings(@RequestBody Map<String,Object> params){
        try {
            colMappingService.updateMappings(params);
            return ResponseMsg.success("success");
        }catch (Exception e){
            e.printStackTrace();
            return ResponseMsg.fail(-1,e.getMessage());
        }
    }


}
